home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earkit / mail / thor / thor25_arexx.lha / MailtoScripts / IBMailTo.thor < prev    next >
Text File  |  1997-08-27  |  8KB  |  265 lines

  1. /*
  2. ** $VER: IBMailTo.thor v1.2ß (21/08/97) John S. Burger (jsburger@xmission.com)
  3. **               <jsburger@xmission.com>
  4. **
  5. ** This script borrows heavily from AwebMailTo.thor by Shaun Downend.
  6. **                  <shaund@amiganut.demon.co.uk>
  7. **                         Thanks Shaun!!!
  8. **
  9. ** This script is designed for use with IBrowse's external mailto: support.
  10. ** It will take the email address supplied by IBrowse and start the text
  11. ** editor of your choice and automatically fill in the To: field. When you
  12. ** have finished you save the message and it will appear as an event in Thor.
  13. **
  14. ** See the .readme file for configuration information.
  15. **
  16. ** V1.1 First public release
  17. ** V1.2 Added ability to specify Thor's FSE as the editor
  18. */
  19.  
  20. /* User defined variables */
  21.  
  22. MailSystem = 'Internet'                              /* Set to your TCP System in Thor                                          */
  23. MailConfName = 'EMail'                               /* Set to your Email Conference in Thor                                    */
  24. AddSignature = 'E'                                   /* Add signature (Y/N/E) from Thor or 'E' for another signature file       */
  25. SigFile = 'DH3:Thor/IB.signature'                    /* File name with path for a signature file used with the 'E' option above */
  26. SendEvent  = 'N'                                     /* Send event immediately (Y/N)                                            */
  27. Editor = 'GED -STICKY C=DH1:GoldEd/config/IB.prefs'  /* Set to the editor of your choice                                        */
  28.                                                      /* Set to FSE to use Thor's internal editor                                */
  29.  
  30.  
  31. /* DON'T CHANGE ANYTHING BELOW HERE */
  32.  
  33. Tempfile = 't:MailTo.msg.'||time(s)'.ib'
  34.  
  35. parse arg argument
  36.  
  37. template = 'ADDRESS/A'
  38.  
  39. if(argument = '' | argument = '?') then
  40. do
  41.     say '$VER: IBMailTo.thor V1.2ß (21/08/97) John S. Burger (jsburger@xmission.com)'
  42.     say 'Template:' template
  43.     exit
  44. end
  45.  
  46. if EDITOR=FSE then do
  47.    p=' '||address()||' '||show('P',,)
  48.    if pos(' THOR.',p)>0 then
  49.    thorport=word(substr(p,pos(' THOR.',p)+1),1)
  50.    else
  51.      do
  52.        call showerror("You have configured this script to use Thor's FSE as the editor. Thor must be running to use this script with FSE!")
  53.        exit
  54.      end
  55. end
  56.  
  57. if ~show('p', 'BBSREAD') then
  58. do
  59.     address command
  60.     "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  61.     "sys:rexxc/WaitForPort BBSREAD"
  62. end
  63.  
  64.  
  65. address BBSREAD
  66.  
  67. READARGS template ARGS CMDLINE argument
  68. if(rc ~= 0) then
  69. do
  70.     say BBSREAD.LASTERROR
  71.     exit
  72. end
  73.  
  74. address command 'echo >'tempfile' "To: 'ARGS.ADDRESS'*NSubject:  *N"'
  75.  
  76. if EDITOR=FSE then do
  77.    address(thorport)
  78.    STARTEDITOR tempfile
  79.    THORTOFRONT
  80.    address command "waitforport THOR_FSE.01"
  81.    address 'THOR_FSE.01'
  82.    SETPOS X 9 Y 2
  83.    INSERTSTRING ' '
  84.      DO WHILE show('p', 'THOR_FSE.01')
  85.         NOP
  86.      END
  87.    END
  88. else
  89.  address command ''Editor' 'tempfile''
  90.  
  91. address BBSREAD
  92.  
  93. if(~OPEN(fh,tempfile,'Read')) then
  94. do
  95.     say 'Unable to open file'
  96.     exit
  97. end
  98.  
  99. str = readln(fh)
  100. if(upper(word(str, 1)) ~= "TO:") | (upper(word(str, 2)) = "") then
  101.  
  102. do
  103.     call showerror("First headerline wasn't a To: or no address was provided after To:,also, there must be a space after To: and the actual address. Please don't mess with the header IBrowse provides.")
  104.     call close(fh)
  105.     address command 'c:delete >NIL: 'tempfile''
  106.     exit
  107. end
  108. else EVENT.TOADDR = word(str, 2)
  109.  
  110. str = readln(fh)
  111.  
  112. if(upper(word(str, 1)) ~= "SUBJECT: ") then
  113. do
  114.     call showerror("Second headerline wasn't a Subject: or there was no space left between Subject: and the actual subject text. Please don't mess with the header IBrowse provides.")
  115.     call close(fh)
  116.     address command 'c:delete >NIL: 'tempfile''
  117.     exit
  118. end
  119. else EVENT.SUBJECT = substr(str, 10)
  120. if(upper(word(str, 2)) = "") then
  121. do
  122.     call showerror("Mail Discarded by User")
  123.     call close(fh)
  124.     address command 'c:delete >NIL: 'tempfile''
  125.     exit
  126. end
  127.  
  128.  
  129. /* put the body of the message in a file with a unique name */
  130.  
  131. UNIQUEMSGFILE bbsname '"'MailSystem'"' stem UNIQUEFILE
  132. if(rc ~= 0) then
  133. do
  134.     call showerror('UNIQUEMSGFILE BBSRead command failed: ' || BBSREAD.LASTERROR)
  135.     call close(fh)
  136.     address command 'c:delete >NIL: 'tempfile''
  137.     exit
  138. end
  139.  
  140. call open(tmp, UNIQUEFILE.NAME, W)
  141.  
  142. do until eof(fh)
  143.     call writeln(tmp, readln(fh))
  144. end
  145.  
  146. /* add signature from the EMail conference/BBS/Global Settings */
  147.  
  148. if(upper(AddSignature) = 'Y') then
  149. do
  150.     GETCONFDATA BBSNAME '"'MailSystem'"' CONFNAME '"'MailConfName'"' STEM CONFD
  151.     if(CONFD.SIGNATURE = "") then
  152.     do
  153.         GETBBSDATA BBSNAME '"'MailSystem'"' STEM BBSD
  154.         if(BBSD.SIGNATURE = "") then
  155.         do
  156.             GETGLOBALDATA STEM GLOBD
  157.             if(GLOBD.SIGNATURE = "") then
  158.             do
  159.                 call showerror('No signature configured in either conference, bbs or global settings! Please correct this in THOR or turn off signature adding in IBMailTo.thor.')
  160.                 call close(fh)
  161.                 address command 'c:delete >NIL: 'tempfile''
  162.                 exit
  163.             end
  164.             else sig = GLOBD.SIGNATURE
  165.         end
  166.         else sig = BBSD.SIGNATURE
  167.     end
  168.     else sig = CONFD.SIGNATURE
  169.  
  170.     drop CONFD.; drop BBSD.; drop GLOBD.
  171.  
  172.     if(sig ~= "") then
  173.     do
  174.     /* signature may be a filename */
  175.  
  176.         if(exists(sig)) then
  177.         do
  178.             call open(sigfh, sig, R)
  179.  
  180.             do until eof(sigfh)
  181.                 call writeln(tmp, readln(sigfh))
  182.             end
  183.  
  184.             call close(sigfh)
  185.         end
  186.         else call writeln(tmp, sig) /* or just a string */
  187.     end
  188. end
  189.  
  190. if(upper(AddSignature) = 'E') then
  191. do
  192.   if(exists(SigFile)) then
  193.   do
  194.      call open(sigfh, SigFile, R)
  195.      do until eof(sigfh)
  196.         call writeln(tmp, readln(sigfh))
  197.      end
  198.      call close(sigfh)
  199.   end
  200.   else
  201.     do
  202.       call showerror('The configured signature file does not exist! Please correct this or turn off signature adding in IBMailTo.thor.')
  203.       call close(fh)
  204.       address command 'c:delete >NIL: 'tempfile''
  205.       exit
  206.     end
  207. end
  208. call close(tmp)
  209.  
  210. /* fill out some more variables that BBSREAD require */
  211.  
  212. EVENT.CONFERENCE = MailConfName
  213. EVENT.MSGFILE = UNIQUEFILE.FILEPART
  214.  
  215. /* write the event */
  216.  
  217. WRITEBREVENT bbsname '"'MailSystem'"' event 0 stem EVENT
  218. if(rc ~= 0) then
  219. do
  220.     call showerror('WRITEBREVENT BBSRead command failed: ' || BBSREAD.LASTERROR)
  221.     call close(fh)
  222.     address command 'c:delete >NIL: 'tempfile''
  223.     exit
  224. end
  225.  
  226. call close(fh)
  227.  
  228. address command 'c:delete >NIL: 'tempfile''
  229.  
  230. if upper(sendevent) = "Y" then call send
  231.  
  232. exit 0
  233.  
  234. /* sophisticated errorhandling :-) */
  235.  
  236. showerror:
  237.  
  238. procedure expose MailSystem MailConfName AddSignature SigFile Editor
  239. parse arg errormsg
  240.  
  241. p=show('P',,)
  242.  
  243. if(pos('IBROWSE', p) > 0) then IBport = word(substr(p, pos('IBROWSE', p)), 1)
  244. else return
  245.  
  246. call open(err, "T:IBMailTo.thor.error.html", W)
  247. call writeln(err, "<HTML><HEAD><TITLE>IBMailTo.thor encountered an error</TITLE></HEAD><BODY><H1>Sending mail aborted</H1>" || errormsg || "<P>Please remember to verify the following settings:<PRE>" || '0a'x '0a'x || "MailSystem = '" || MailSystem || "'" || '0a'x || "MailConfName = '" || MailConfName || "'" || '0a'x || "AddSignature = '" || AddSignature || "'" || '0a'x || "SigFile = '" || SigFile || "'" || '0a'x || "Editor = '" || Editor || "'" || '0a'x '0a'x || "</PRE>If they are wrong, edit IBMailTo.thor and correct them. <hr> If this should happen to be an erroneous error, don't hesitate to contact the author, John S. Burger, by <A HREF=" || '"' || "mailto:jsburger@xmission.com" || '"' || ">email</A>.")
  248. call close(err)
  249.  
  250. address(IBport)
  251. 'GOTOURL URL file://localhost/T:IBMailTo.thor.error.html'
  252. 'SCREENTOFRONT'
  253. return
  254.  
  255. send:
  256.  
  257. If Show('p', 'AMITCP') | Show('p', 'MIAMI.1') = 1 then
  258. do
  259.     address BBSREAD
  260.     GETBBSDATA SystemName stem BBSDATA
  261.     if BBSDATA.NUMEVENTS ~= 0 then
  262.     address command 'run >NIL: `getenv thor/thorpath`bin/SendTCP 'MailSystem' pubscreen=Workbench'
  263. end
  264. return
  265.